using System.Text.Json.Serialization;

namespace MVCWeekOne.Models
{
    /// <summary>
    /// 用户信息模型
    /// </summary>
    public class UserModel
    {
        [JsonPropertyName("id")]
        public int Id { get; set; }

        [JsonPropertyName("userName")]
        public string UserName { get; set; } = string.Empty;

        [JsonPropertyName("realName")]
        public string RealName { get; set; } = string.Empty;

        [JsonPropertyName("email")]
        public string? Email { get; set; }
    }

    /// <summary>
    /// 不良品查询参数
    /// </summary>
    public class DefectiveQueryModel
    {
        [JsonPropertyName("defectiveCode")]
        public string? DefectiveCode { get; set; }

        [JsonPropertyName("defectiveName")]
        public string? DefectiveName { get; set; }

        [JsonPropertyName("pageIndex")]
        public int PageIndex { get; set; } = 1;

        [JsonPropertyName("pageSize")]
        public int PageSize { get; set; } = 10;
    }

    /// <summary>
    /// 不良品高级查询参数
    /// </summary>
    public class DefectiveAdvancedQueryModel
    {
        [JsonPropertyName("defectiveCode")]
        public string? DefectiveCode { get; set; }

        [JsonPropertyName("defectiveName")]
        public string? DefectiveName { get; set; }

        [JsonPropertyName("pageIndex")]
        public int PageIndex { get; set; } = 1;

        [JsonPropertyName("pageSize")]
        public int PageSize { get; set; } = 10;
    }

    /// <summary>
    /// 不良品项DTO
    /// </summary>
    public class DefectiveDto
    {
        [JsonPropertyName("id")]
        public int Id { get; set; }

        [JsonPropertyName("defectiveCode")]
        public string DefectiveCode { get; set; } = string.Empty;

        [JsonPropertyName("defectiveName")]
        public string DefectiveName { get; set; } = string.Empty;

        [JsonPropertyName("attachmentPath")]
        public string? AttachmentPath { get; set; }

        [JsonPropertyName("imagePath")]
        public string? ImagePath { get; set; }

        [JsonPropertyName("createTime")]
        public DateTime CreateTime { get; set; }

        [JsonPropertyName("creatorId")]
        public int CreatorId { get; set; }

        [JsonPropertyName("modifierId")]
        public int? ModifierId { get; set; }

        [JsonPropertyName("modifyTime")]
        public DateTime? ModifyTime { get; set; }

        // 用户信息（通过联查获取）
        [JsonPropertyName("creator")]
        public UserModel? Creator { get; set; }

        [JsonPropertyName("modifier")]
        public UserModel? Modifier { get; set; }

        // 为了兼容前端显示，添加计算属性
        [JsonPropertyName("attachment")]
        public string Attachment => AttachmentPath ?? string.Empty;
        
        [JsonPropertyName("image")]
        public string Image => ImagePath ?? string.Empty;
        
        [JsonPropertyName("createBy")]
        public string CreateBy => Creator?.RealName ?? Creator?.UserName ?? CreatorId.ToString();
        
        [JsonPropertyName("updateBy")]
        public string UpdateBy => Modifier?.RealName ?? Modifier?.UserName ?? ModifierId?.ToString() ?? string.Empty;
        
        [JsonPropertyName("updateTime")]
        public DateTime? UpdateTime => ModifyTime;
    }

    /// <summary>
    /// 不良品分页结果
    /// </summary>
    public class DefectivePageResult
    {
        [JsonPropertyName("msg")]
        public string Msg { get; set; } = string.Empty;

        [JsonPropertyName("code")]
        public int Code { get; set; }

        [JsonPropertyName("totaCount")]
        public int TotaCount { get; set; }

        [JsonPropertyName("totaPage")]
        public int TotaPage { get; set; }

        [JsonPropertyName("pageData")]
        public List<DefectiveDto> PageData { get; set; } = new List<DefectiveDto>();
    }

    /// <summary>
    /// 新增不良品请求模型
    /// </summary>
    public class AddDefectiveRequest
    {
        [JsonPropertyName("defectiveCode")]
        public string DefectiveCode { get; set; } = string.Empty;

        [JsonPropertyName("defectiveName")]
        public string DefectiveName { get; set; } = string.Empty;

        [JsonPropertyName("attachmentPath")]
        public string? AttachmentPath { get; set; }

        [JsonPropertyName("imagePath")]
        public string? ImagePath { get; set; }

        [JsonPropertyName("creatorId")]
        public int CreatorId { get; set; }
    }

    /// <summary>
    /// 新增不良品响应模型
    /// </summary>
    public class AddDefectiveResponse
    {
        [JsonPropertyName("msg")]
        public string Msg { get; set; } = string.Empty;

        [JsonPropertyName("code")]
        public int Code { get; set; }

        [JsonPropertyName("data")]
        public int Data { get; set; }
    }

    /// <summary>
    /// 更新不良品请求模型
    /// </summary>
    public class UpdateDefectiveRequest
    {
        [JsonPropertyName("id")]
        public int Id { get; set; }

        [JsonPropertyName("defectiveCode")]
        public string DefectiveCode { get; set; } = string.Empty;

        [JsonPropertyName("defectiveName")]
        public string DefectiveName { get; set; } = string.Empty;

        [JsonPropertyName("attachmentPath")]
        public string? AttachmentPath { get; set; }

        [JsonPropertyName("imagePath")]
        public string? ImagePath { get; set; }

        [JsonPropertyName("modifierId")]
        public int ModifierId { get; set; }
    }

    /// <summary>
    /// 批量删除不良品请求模型
    /// </summary>
    public class DeleteDefectiveRequest
    {
        [JsonPropertyName("ids")]
        public List<int> Ids { get; set; } = new List<int>();
    }

    /// <summary>
    /// 删除不良品响应模型
    /// </summary>
    public class DeleteDefectiveResponse
    {
        [JsonPropertyName("msg")]
        public string Msg { get; set; } = string.Empty;

        [JsonPropertyName("code")]
        public int Code { get; set; }

        [JsonPropertyName("data")]
        public int Data { get; set; }
    }
}
